<script lang="ts" setup>
import { Plus } from '@element-plus/icons-vue'
import { getDictType,delDictType } from '@/api/modules/system'
import addTask from './components/addTask.vue'
const pageNum = ref(1)
const total = ref(0)
const dialogVisible = ref(false)
const rows = ref<any>({})
const tableData = ref([])
const view = ref('add')
async function getList() {
  tableData.value = [
    {
      name: '张三',
      jobNo: '123456',
      carNo: '999999999',
      department: '业务部 1',
      duty: '总经理 1',
      staffStatus: '在职',
      isTemplate: '否',
      wellStar: '2023-01-01',
      wellEnd: '2023-01-01',
      wellTime: '30分钟'
    }
  ]
    total.value = 1
  // const params = {
  //   pageNum: pageNum.value,
  //   pageSize: 10,
  //   data: {
  //     ...formData.value,
  //   }
  // }
  // const res = await getDictType(params)
  // if (res.code === 200) {
  //   tableData.value = res.data.records
  //   total.value = res.data.totalPage
  // }
}
function handleSearch() {
  pageNum.value = 1
  // getList()
}
function handleDetails(row: object) {
  rows.value = row
  dialogVisible.value = true
}

function handleDetle(row: any) {
  tableData.value = tableData.value.filter((item: any) => item.id !== row.id)
}

function handleCurrentChange(val: number) {
  pageNum.value = val
  // getList()
}

function handleConcel(flag: Boolean) {
  dialogVisible.value = false
  if(flag) {
    getList()
  }
}

getList()
</script>

<template>
  <div>
    <ContentWrap>
      <div style="margin-bottom: 10px;">
        <el-button type="primary" :icon="Plus" @click="rows = {}; dialogVisible = true">
          添加任务
        </el-button>
      </div>
      <el-table
        :data="tableData"
        border
        style="width: 100%;"
      >
        <el-table-column type="index" label="序号" width="60" align="center" />
        <el-table-column prop="name" label="任务名称" min-width="150" align="center" />
        <el-table-column prop="jobNo" label="执行模版" min-width="200" align="center" />
        <el-table-column prop="carNo" label="执行时间" min-width="150" align="center" />
        <el-table-column align="center" label="操作" min-width="100">
          <template #default="scope">
            <el-button size="small" type="primary" @click="handleDetails(scope.row)">
              修改
            </el-button>
            <el-popconfirm title="确定删除该条数据?" @confirm="handleDetle(scope.row)">
              <template #reference>
                <el-button size="small" type="danger">
                  删除
                </el-button>
              </template>
            </el-popconfirm>
          </template>
        </el-table-column>
      </el-table>
      <div class="page-wrap">
        <!-- <el-pagination
          background
          layout="total, prev, pager, next, jumper"
          :total="Number(total)"
          :page-size="10"
          :current-page="pageNum"
          @current-change="handleCurrentChange"
        /> -->
        <Pagination
        :limit="10"
        :page="pageNum"
        :total="(total)"
        @pagination="handleCurrentChange"
        />
      </div>
    </ContentWrap>
    <el-dialog v-model="dialogVisible" :title="rows.id ? '编辑任务' : '添加任务'" width="500px">
      <add-task v-if="dialogVisible" :data="rows" :viewType="view" @concel="handleConcel" />
      <!-- <add-dict-type @concel="closeDialog" :rows="rows" :visible="dialogVisible" /> -->
    </el-dialog>
  </div>
</template>
